/**
 * Created by wdj on 16/4/21.
 * IndexController
 */
'use strict';
var Controller = require('../Controller');
// var Utils = require('utils');
var hybrid = require('dao6-hybrid');
var $ = Dom7;

/* 模拟数据 */
var lists = {
    jobs: [
        {title: '张三', avatar: 'http://statics.maosui.com/Res/ResReadOlnyServer.ashx?key=/Common/20160411/fc591825d79d45a496e74faafb11f11f.png', img: 'http://img0.imgtn.bdimg.com/it/u=1680497829,391676469&fm=21&gp=0.jpg'},
        {title: '李四', img: 'http://statics.maosui.com/Res/ResReadOlnyServer.ashx?key=/Common/20160103/63a979900f9d410da6e4b26e41211592.jpg',text: '我要买台iPhone 6s'},
        {title: '王二', img: 'http://statics.maosui.com/Res/ResReadOlnyServer.ashx?key=/Common/20151029/a8e7b355cf154dd6993fb7ebf1ba8c47.jpg', text: '我要买奶粉'},
        {title: '麻子', text: '求购MacBook Air 2020', img: 'http://img0.imgtn.bdimg.com/it/u=1680497829,391676469&fm=21&gp=0.jpg'},
        {title: '赵六', text: 'a strong open vehicle with two or four wheels, typically used for carrying loads and pulled by a horse.'},
        {title: '刘一刀', text: 'convey or put in a cart or similar vehicle.', img: 'http://img0.imgtn.bdimg.com/it/u=1680497829,391676469&fm=21&gp=0.jpg'},
        {title: '马子妮', text: 'carry (a heavy or cumbersome object) somewhere with difficulty.'},
        {title: '豆可可', text: 'they carted the piano down three flights of stairs', img: 'http://img0.imgtn.bdimg.com/it/u=1680497829,391676469&fm=21&gp=0.jpg'},
    ]
};

class IndexController extends Controller {

    onCreated(app, page) {

        var IndexListView = this.importView('view/index_list');
        this.find('#home-list-content').html(IndexListView(lists));

        $('.pull-to-refresh-content').on('refresh', ()=>{
            setTimeout(()=>{
                app.pullToRefreshDone();
                hybrid.makeToast('数据已刷新');
            }, 2000)
        });

        $('.infinite-scroll').on('infinite', ()=>{
            setTimeout(()=>{
                //app.detachInfiniteScroll(Dom7('.infinite-scroll'));
                // 删除加载提示符
                // Dom7('.infinite-scroll-preloader').remove();
                this.find('#home-list-content').append(IndexListView(lists))
            }, 1000)
        });

        $(document.body).on('click', '.popover-links a.item-link', function () {
            // console.log(this.innerText);
            $('#city-popover span').html(this.innerText);
        });

        this.bindEvents({
            'click #home-list-content(a.share-link)':function () {

                hybrid.Social.showShareActionSheet({
                    title: '分享标题',
                    text: '分享文字内容',
                    image: 'http://statics.maosui.com/Res/ResReadOlnyServer.ashx?key=/Common/20151029/a8e7b355cf154dd6993fb7ebf1ba8c47.jpg',
                    url: 'https://www.wendaojiang.com',
                });
            }
        })
    }
}

export const _ = IndexController;

module.exports = IndexController;
